import time, sys
import RPi.GPIO as GPIO

channel = 7
GPIO.setmode(GPIO.BOARD)
GPIO.setup(channel, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
flag = True

def action(channel):
    global flag
    flag = False

GPIO.add_event_detect(channel, GPIO.RISING)
GPIO.add_event_callback(channel, action)

try:
    for i in range(10):
        print(flag)
        time.sleep(0.5)
except KeyboardInterrupt:
    GPIO.cleanup()
